package com.spt.springbootzhsx.dao;

import com.spt.springbootzhsx.entity.Plan;
import com.spt.springbootzhsx.entity.back.PlanBack;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.ArrayList;
import java.util.Date;

@Mapper
public interface PlanDao {
    @Select("select plan.pid,plan.mid,plan.cid,price,playTime,mrole,director,rate,desn,duration,mname,pic,mtype,mlanguage,mstate,cname,crow,ccolumn " +
            "from movie,cinema,plan " +
            "where plan.mid=movie.mid and plan.cid=cinema.cid")
    ArrayList<PlanBack> getAllPlan();

    @Select("select plan.pid,plan.mid,plan.cid,price,playTime,mrole,director,rate,desn,duration,mname,pic,mtype,mlanguage,mstate,cname,crow,ccolumn " +
            "from movie,cinema,plan " +
            "where plan.mid=movie.mid and plan.cid=cinema.cid and playTime>now()")
    ArrayList<PlanBack> getAllPlanNow();

    @Select("select plan.pid,plan.mid,plan.cid,price,playTime,mrole,director,rate,desn,duration,mname,pic,mtype,mlanguage,mstate,cname,crow,ccolumn " +
            "from movie,cinema,plan " +
            "where plan.mid=movie.mid and plan.cid=cinema.cid and mname=#{mname}")
    ArrayList<PlanBack> getPlanByMname(String mname);

    @Select("select plan.pid,plan.mid,plan.cid,price,playTime,mrole,director,rate,desn,duration,mname,pic,mtype,mlanguage,mstate,cname,crow,ccolumn " +
            "from movie,cinema,plan " +
            "where plan.mid=movie.mid and plan.cid=cinema.cid and mname=#{mname} and playTime>now()")
    ArrayList<PlanBack> getPlanByMnameNow(String mname);

    @Select("select plan.pid,plan.mid,plan.cid,price,playTime,mrole,director,rate,desn,duration,mname,pic,mtype,mlanguage,mstate,cname,crow,ccolumn " +
            "from movie,cinema,plan " +
            "where plan.mid=movie.mid and plan.cid=cinema.cid and cname=#{cname}")
    ArrayList<PlanBack> getPlanByCname(String cname);

    @Select("select plan.pid,plan.mid,plan.cid,price,playTime,mrole,director,rate,desn,duration,mname,pic,mtype,mlanguage,mstate,cname,crow,ccolumn " +
            "from movie,cinema,plan " +
            "where plan.mid=movie.mid and plan.cid=cinema.cid and cname=#{cname} and playTime>now()")
    ArrayList<PlanBack> getPlanByCnameNow(String cname);

    @Select("select plan.pid,plan.mid,plan.cid,price,playTime,mrole,director,rate,desn,duration,mname,pic,mtype,mlanguage,mstate,cname,crow,ccolumn " +
            "from movie,cinema,plan " +
            "where plan.mid=movie.mid and plan.cid=cinema.cid and plan.mid=#{mid} and playTime>#{st} and playTime<#{ed}")
    ArrayList<PlanBack> getPlanByMidAndDate(@Param("mid") Integer mid,@Param("st") Date st,@Param("ed") Date ed);

    @Select("select plan.pid,plan.mid,plan.cid,price,playTime,mrole,director,rate,desn,duration,mname,pic,mtype,mlanguage,mstate,cname,crow,ccolumn " +
            "from movie,cinema,plan " +
            "where plan.mid=movie.mid and plan.cid=cinema.cid and pid=#{pid}")
    PlanBack getPlanByPid(Integer pid);
}
